package BeenChina.PM.Util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.codec.binary.Base64;

public class EncodeDownLoadFileName {
	 public   static  String encode(HttpServletRequest request, String fileName)  throws  UnsupportedEncodingException {  
		String agent = request.getHeader("USER-AGENT" );  
		if( null  != agent && - 1  != agent.indexOf( "MSIE" )) {  
		    return  URLEncoder.encode(fileName,  "UTF8" );  
		}
		else if  ( null  != agent && - 1  != agent.indexOf( "Firefox" )) {  
		    return   "=?UTF-8?B?" +( new  String(Base64.encodeBase64(fileName.getBytes( "UTF-8" ))))+ "?=" ;  
		} 
		else if  ( null  != agent && - 1  != agent.indexOf( "Chrome" )) { 
		    return  new String(fileName.getBytes(), "ISO8859-1");  		 		    	
		}  
		else{
			return fileName;
		}
	 }   
}